<?php
/* $Id: genconfig.php,v 1.1 JOP $ */
/**
 * @package Issue-Tracker
 * @subpackage Admin
 */

if (strpos($_SERVER['PHP_SELF'],basename(__FILE__)) !== false) {
  print "Direct module access forbidden.".basename(__FILE__);exit;}
  

// Make sure user is an admin
if (!is_admin()) {
  redirect();
}

$cid = $_GET['cid'];

if (!empty($_POST['catid'])) {
//if ($_GET['submit'] == "true") {

  $sql  = "SELECT pid ";
  $sql .= "FROM z_param ";
  $sql .= "ORDER BY pid DESC ";
  $last = $dbi->fetch_one($sql);

  if (!errors()) {
     for ($x = 1;$x <= $last;$x++) {
          if (!empty($_POST['param'.$x])) {
             $ptype = getfield('z_param','input_type','pid',$x);
             if ($ptype == 'checkbox') {
                $cfg['value'] = $_POST['value'.$x] == "on" ? "t" : "f";
             } else {
               $cfg['value'] = $_POST['value'.$x];
             }
             $dbi->update("z_param",$cfg,"WHERE pid='".$x."'");
             unset($cfg);
          }
     }
  redirect("?module=admin&action=genconfig&cid=".$cid);
  }
}


// Retrieve/push config parameters
    $sql  = "SELECT * ";
    $sql .= "FROM z_param ";
    $sql .= "WHERE cid=".$cid;
    $params = $dbi->fetch_all($sql,"array");

$smarty->assign('cid',$cid);
$smarty->assign('ctitle',$config_menu);
$smarty->assign('params',$params);

$smarty->display("admin/genconfig.tpl");
?>